//
// Created by Administrator on 2021/11/23.
// May Saint Diana bless you!
//
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <climits>

using namespace std;

class Solution {
public:
    int minTimeToType(string word) {
        char prev = 'a';
        int ans = 0;
        for (char i: word) {
            int length = abs(i - prev);
            ans += min(length, 26 - length)+1;
            prev = i;
        }
        return ans;
    }
};

int main() {
    Solution solution;
    cout << solution.minTimeToType("abc") << endl;
    cout << solution.minTimeToType("bza") << endl;
    cout << solution.minTimeToType("zjpc") << endl;
    return 0;
}
